﻿using System.Web;

namespace Rogan.Common
{
    public class WebMessageBox
    {
        /// <summary>
        /// 网页消息对话框
        /// </summary>
        /// <param name="Message">要显示的消息文本</param>
        public static void Show(string Message)
        {
            HttpContext.Current.Response.Write("<script language='javascript' type='text/javascript'>alert('" + Message + "')</script>");
            HttpContext.Current.Response.Write("<script>history.go(-1)</script>");
            HttpContext.Current.Response.End();
        }

        /// <summary>
        /// 网页消息对话框
        /// </summary>
        /// <param name="Message">要显示的消息文本</param>
        /// <param name="Src">点击确定后跳转的页面</param>
        public static void Show(string Message, string Src)
        {
            HttpContext.Current.Response.Write("<script language='javascript' type='text/javascript'>alert('" + Message + "');location.href='" + Src + "'</script>");
            HttpContext.Current.Response.End();
        }

        /// <summary>
        /// 网页消息对话框
        /// </summary>
        /// <param name="Message">要显示的消息文本</param>
        /// <param name="Close">关闭当前页面</param>
        public static void Show(string Message, bool Close)
        {
            if (Close)
            {
                HttpContext.Current.Response.Write("<script language='javascript' type='text/javascript'>alert('" + Message + "');window.close()</script>");
                HttpContext.Current.Response.End();
            }
            else
            {
                HttpContext.Current.Response.Write("<script language='javascript' type='text/javascript'>alert('" + Message + "')</script>");
                HttpContext.Current.Response.End();
            }
        }

        /// <summary>
        /// 后台文本框输入危险字符报错
        /// </summary>
        public static void InputWorry()
        {
            HttpContext.Current.Response.Write("{\"statusCode\":\"300\", \"message\":\"操作失败，请尽量不要输入特殊字符\"," +
                 " \"navTabId\":\"\", \"rel\":\"\",\"callbackType\":" +
                 "\"\",\"forwardUrl\":\"\"}");
        }

        /// <summary>
        /// DWZ操作成功或失败提示框
        /// </summary>
        /// <param name="isRight"></param>
        /// <param name="closeCurrent"></param>
        /// <param name="navTabId"></param>
        /// <param name="rel"></param>
        /// <param name="forwardUrl"></param>
        public static void DWZMessage(bool isRight, bool closeCurrent, string navTabId, string rel, string forwardUrl)
        {
            if (isRight == false)
            {
                HttpContext.Current.Response.Write("{\"statusCode\":\"300\", \"message\":\"操作失败\"," +
                 " \"navTabId\":\"\", \"rel\":\"\",\"callbackType\":" +
                 "\"\",\"forwardUrl\":\"\"}");
            }
            else if (isRight)
            {
                string close = closeCurrent ? "closeCurrent" : "";
                HttpContext.Current.Response.Write("{\"statusCode\":\"200\", \"message\":\"操作成功\"," +
                    " \"navTabId\":\"" + navTabId + "\", \"rel\":\"" + rel + "\",\"callbackType\":" +
                    "\"" + close + "\",\"forwardUrl\":\"" + forwardUrl + "\"}");
            }
        }

        /// <summary>
        /// DWZ操作成功或失败提示框
        /// </summary>
        /// <param name="isRight"></param>
        /// <param name="closeCurrent"></param>
        /// <param name="navTabId"></param>
        /// <param name="rel"></param>
        /// <param name="forwardUrl"></param>
        public static void DWZMessage(bool isRight, bool closeCurrent, string navTabId, string rel, string forwardUrl, string errorMsg)
        {
            if (isRight == false)
            {
                HttpContext.Current.Response.Write("{\"statusCode\":\"300\", \"message\":\"" + errorMsg + "\"," +
                 " \"navTabId\":\"\", \"rel\":\"\",\"callbackType\":" +
                 "\"\",\"forwardUrl\":\"\"}");
            }
            else if (isRight)
            {
                string close = closeCurrent ? "closeCurrent" : "";
                HttpContext.Current.Response.Write("{\"statusCode\":\"200\", \"message\":\"操作成功\"," +
                    " \"navTabId\":\"" + navTabId + "\", \"rel\":\"" + rel + "\",\"callbackType\":" +
                    "\"" + close + "\",\"forwardUrl\":\"" + forwardUrl + "\"}");
            }
        }
    }
}
